package com.shelpe.services.algorithm.client;

import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.shelpe.services.algorithm.client.SimbaProxyClient.SimbaProxyClientFallback;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@FeignClient(name="${feign.simba.name}", url="${feign.simba.url}", fallback = SimbaProxyClientFallback.class)
public interface SimbaProxyClient {

	@RequestMapping(path = "/simba/taobao.simba.insight.catsdata.get", method = RequestMethod.GET,  consumes="application/json;charset=UTF-8")
	CategoryDataResponse findCategoryData(@RequestParam("category_id_list") List<String> categoryIDs, @RequestParam("start_date")String startDate, 
			@RequestParam("end_date")String endDate, @RequestHeader("tenantID") long tenantID);
	
	@Data
	public static class CategoryDataResponse{
		
		@JsonProperty("simba_insight_catsdata_get_response")
		private CategoryDataRes res;
	}
	
	@Data
	public static class CategoryDataRes{
		@JsonProperty("cat_data_list")
		private CategoryWordDatas datas;
	}
	
	@Data
	public static class CategoryWordDatas{
		@JsonProperty("insight_category_data_d_t_o")
		private List<InsightWordData> wordDatas;
	}
	
	@RequestMapping(path = "/simba/taobao.simba.insight.wordsdata.get", method = RequestMethod.GET)
	GlobalWordRespone findGlobalData(@RequestParam("bidword_list") List<String> words, @RequestParam("start_date")String startDate, 
			@RequestParam("end_date")String endDate, @RequestHeader("tenantID") long tenantID);
	
	@Getter
	@Setter
	public static class GlobalWordRespone{		
		@JsonProperty("simba_insight_wordsdata_get_response")
		private GlobalWordRes res;
	}
	
	@Getter
	@Setter
	public static class GlobalWordRes{		
		@JsonProperty("word_data_list")
		private GlobalWordDataList dataList;
	}
	
	@Data
	public class GlobalWordDataList {
		@JsonProperty("insight_word_data_d_t_o")
		private List<InsightWordData> words;
	}


	@Service
	@Slf4j
	public static class SimbaProxyClientFallback implements SimbaProxyClient{

		@Override
		public CategoryDataResponse findCategoryData(List<String> categoryIDs, String startDate, String endDate,
				long tenantID) {
			log.error("fallback findCategoryData: {}", categoryIDs);
			return new CategoryDataResponse();
		}

		@Override
		public GlobalWordRespone findGlobalData(List<String> words, String startDate, String endDate,
				long tenantID) {
			log.error("fallback findGlobalData: {}", words);
			return new GlobalWordRespone();
		}
		
	}
}
